package com.lss.fmap.repository;

import android.app.Application;

import androidx.lifecycle.LiveData;

import com.lss.fmap.model.Accounting;
import com.lss.fmap.model.AccountingDao;
import com.lss.fmap.model.AppDatabase;

import java.util.List;

public class AccountingRepository {
    private AccountingDao accountingDao;
    private LiveData<List<Accounting>> allAccountings;

    public AccountingRepository(Application application) {
        AppDatabase database = AppDatabase.getInstance(application);
        accountingDao = database.accountingDao();
        allAccountings = accountingDao.getAllAccountings();
    }

    public void insert(Accounting accounting) {
        new Thread(() -> {
            accountingDao.insert(accounting);
        }).start();
    }

    public void deleteAll() {
        new Thread(() -> {
            accountingDao.deleteAll();
        }).start();
    }

    public LiveData<List<Accounting>> getAllAccountings() {
        return allAccountings;
    }
}
